package com.supermarket_project.controller;

import com.supermarket_project.common.R;
import com.supermarket_project.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/supermarket")
public class ActivityController {

    @Autowired
    ActivityService activityService;

    /**
     * 获取所有活动的信息
     * @return
     */
    @RequestMapping(value = "getAllActivityInfo",method = RequestMethod.GET)
    public R getAllActivityInfo_c(){
        R r=new R();
        r=activityService.getAllActivityInfo_s();
        return r;
    }

    /**
     * 添加一个活动
     * @param activity_map
     * @return
     */
    @RequestMapping(value = "addOneActivity",method = RequestMethod.POST)
    public R addOneActivity_c(@RequestBody Map activity_map){
        R r=new R();
        r=activityService.addOneActivity_s(activity_map);
        return r;
    }

    /**
     * 改变活动的状态，开启，关闭活动
     * @param activity_id_map
     * @return
     */
    @RequestMapping(value = "updateActivityStatus",method = RequestMethod.POST)
    public R updateActivityStatus_c(@RequestBody Map activity_id_map){
        R r=new R();
        r=activityService.updateActivityStatus_s(Long.parseLong(activity_id_map.get("activity_id").toString()));
        return r;
    }

    /**
     * 删除活动
     * @param delete_info_map
     * @return
     */
    @RequestMapping(value = "deleteActivity",method = RequestMethod.POST)
    public R deleteActivity_c(@RequestBody Map delete_info_map){
        R r=new R();
        r=activityService.deleteActivity_s(delete_info_map);
        return r;
    }

    /**
     * 生成条形码
     * @param activity_name_map
     * @return
     */
    @RequestMapping("produceBarCode")
    public R produceBarCode_c(@RequestBody Map activity_name_map){
        return null;
    }
}
